﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


//using Microsoft.AspNet.Identity.EntityFramework;

using System.Data.Entity;
using System.Data.Entity.ModelConfiguration;
using System.Reflection;
using Registro.Compras.Data.Entities;

//using Registro.Compras.Data.Managers;

namespace Registro.Compras.Data
{
    public class RegistroComprasDbContext : DbContext
    {
        public RegistroComprasDbContext()
            : base("DefaultConnection")
        {

        }

        static RegistroComprasDbContext()
        {
            // Set the database intializer which is run once during application start
        }
        


        public static RegistroComprasDbContext Create()
        {
            return new RegistroComprasDbContext();
        }

        public DbSet<Base1> Base1s { get; set; }
        public DbSet<ReferenciaComprobante> ReferenciaComprobantes { get; set; }
        public DbSet<Tabla10> Tabla10s { get; set; }
        public DbSet<Tabla2> Tabla2s { get; set; }
        public DbSet<Proveedor> Proveedores { get; set; }
        public DbSet<Encabezado> Encabezados { get; set; }
        public DbSet<BaseImponible> BaseImponibles { get; set; }
        public DbSet<Elemento> Elementos { get; set; }
        

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            var typesToRegister = Assembly.GetExecutingAssembly().GetTypes()
           .Where(type => !String.IsNullOrEmpty(type.Namespace))
           .Where(type => type.BaseType != null && type.BaseType.IsGenericType
                && type.BaseType.GetGenericTypeDefinition() == typeof(EntityTypeConfiguration<>));
            foreach (var type in typesToRegister)
            {
                dynamic configurationInstance = Activator.CreateInstance(type);
                modelBuilder.Configurations.Add(configurationInstance);
            }
            base.OnModelCreating(modelBuilder);
        }


    }
}
